package CommonClasses.StringClass;

import org.testng.annotations.Test;

public class StrOperatre {

    public  String trim(String str){
        if(str==""){
            return "";
        }
        char[] s=str.toCharArray();
        int l=str.length();
        int start=0,end=l-1;
        while(s[start]==' '){
            start++;
            if(start>=end){
                break;
            }
        }
        while(s[end]==' '){
            end--;
            if(end<=0){
                break;
            }
        }
        if(start>=end){
            return "";
        }
        StringBuilder sb=new StringBuilder();
        for(int i=start;i<=end;i++){
            sb.append(s[i]);
        }
        return sb.toString();
    }
    @Test
    public void trimMain(){
        System.out.println(trim("  java android  "));
        System.out.println(trim("java android  "));
        System.out.println(trim("  "));
        System.out.println(trim(""));
    }


    public String toLower1(String str){
        char[] s=str.toCharArray();
        for(int i=0;i<str.length();i++){
            if(s[i]>=65 && s[i] <= 90){
                s[i]+=32;
            }
        }
        return new String(s);
    }
    public String toLower2(String str){
        char[] s=str.toCharArray();
        for(int i=0;i<str.length();i++){
            if(Character.isUpperCase(s[i])){
                s[i]=Character.toLowerCase(s[i]);
            }
        }
        return new String(s);
    }

    @Test
    public void toLowerMain(){
        System.out.println(toLower1("I Love Java！"));
        System.out.println(toLower2("I Love Java！"));
    }
}
